﻿#region Using Statements
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; 
#endregion

namespace kinect_music_shooter.GameWorld
{
    public class GameObject
    {
        #region Fields

        public Model model = null;
        public BoundingSphere boundingSphere;

        public float scale = 1.0f;
        public Vector3 position = Vector3.Zero;
        public Vector3 rotation = Vector3.Zero;
        public Vector3 velocity = Vector3.Zero;
        
        #endregion

        public void loadModel(Model pModel)
        {
            model = pModel;
            boundingSphere = model.Meshes[0].BoundingSphere;
            boundingSphere.Radius *= scale;
        }

        #region Update and Draw

        public virtual void Draw(GraphicsDevice graphicsDevice, Camera camera)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;

                    effect.World =
                        Matrix.CreateFromYawPitchRoll(
                        rotation.Y,
                        rotation.X,
                        rotation.Z) *

                        Matrix.CreateScale(scale) *

                        Matrix.CreateTranslation(position);

                    effect.DirectionalLight0.DiffuseColor = new Vector3(0.1f, 0.1f, 0.1f); // a red light
                    effect.DirectionalLight0.Direction = new Vector3(5, -5, -10);  // coming along the x-axis
                    effect.DirectionalLight0.SpecularColor = new Vector3(1, 0, 0); // with red highlights
                    effect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f);
                    effect.EmissiveColor = new Vector3(0.2f, 0.2f, 0.2f);

                    effect.Projection = camera.Projection;
                    effect.View = camera.View;
                }
                mesh.Draw();
            }
        }

        /*public virtual void Update()
        {
        }*/

        #endregion
    }
}
